/*
 * @Description:注册微应用
 * @Date: 2023-02-16 17:27:52
 */
import { registerMicroApps, setDefaultMountApp } from 'qiankun'
import { withLoading } from '@/components/Loading'
import { ElLoading } from 'element-plus'
import actions from './actions'
import 'element-plus/theme-chalk/el-loading.css'
const { MODE } = import.meta.env
// 应用加载
let loading
/**
 * 微应用列表
 */
const microApps = [
  {
    name: 'lawsuit',
    entry: MODE === 'development' ? '//127.0.0.1:1001' : '/lawsuit/',
    activeRule: '/lawsuit'
  },
  {
    name: 'auth',
    entry: MODE === 'development' ? '//127.0.0.1:1002' : '/auth/',
    activeRule: '/auth'
  }
]
/**
 * 注册微应用
 * https://qiankun.umijs.org/zh/api#registermicroappsapps-lifecycles
 */
registerMicroApps(
  microApps.map((app) => {
    return {
      ...app,
      container: '#micro-container',
      props: {
        actions,
        _parent_base: '/'
        // getGlobalState: store.getGlobalState,//下发公共信息
      }
    }
  }),
  {
    beforeLoad: [
      (app) => {
        loading = ElLoading.service({
          lock: true,
          text: '应用加载中',
          background: 'rgba(0, 0, 0, 0.1)',
          target: '#main'
        })
      }
    ],
    beforeMount: [
      (app) => {
        console.log(app.name)
      }
    ],
    afterMount: [
      (app) => {
        loading.close()
      }
    ],
    afterUnmount: [(app) => {}]
  }
)

/**
 * 设置默认进入的子应用
 */
// setDefaultMountApp("/auth");
// start({
//   sandbox: {
//     experimentalStyleIsolation: true,
//   },
// });
